-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QuickEdit: Add Featured Image Control #64496
Conversation
2133ef7
to
0a2c977
Compare
Hey @jameskoster, I've implemented your suggestion: Screen.Capture.on.2024-08-22.at.15-42-51.mp4Let me know if, from the design perspective, there is something to address. I’m not marking this PR as ready for review because we still need to implement the default edit control for the image field. Since DataViews is a general-purpose library, we shouldn’t rely on the WordPress Media Gallery for the generic control. Instead, I suggest using the Operating System’s file selection option: Screen.Capture.on.2024-08-22.at.15-52-20.mp4However, please note that in this case, we won’t have access to the filename once the file is uploaded. |
0a2c977
to
c32622e
Compare
Thanks for the update. The flow seems pretty good, but there are some design details to fix.
Also here:
Here's a mockup that hopefully clarifies some of the details: |
With 9a39fe6, I addressed your feedback! Screen.Capture.on.2024-08-23.at.10-14-17.mp4The only remaining challenge is that the filename can only be truncated to a fixed number of characters, which may result in it not always ending directly under the remove button. |
event.target.tagName.toLowerCase(); | ||
// Prevent opening the media modal when clicking on the button/icon. | ||
if ( | ||
element !== 'button' && | ||
element !== 'svg' | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that there's a button within a clickable area, and clicking the button triggers a separate action. I'm not sure if this is the best way to handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render={ ( { open } ) => { | ||
return ( | ||
<div | ||
role="button" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related comment: https://github.com/WordPress/gutenberg/pull/64496/files#r1728584779
As I mentioned in the previous comment, this could be complex to achieve given that
Do you mean something like this? |
The documentation says that when ´Limit` is the max number of characters to be displayed: So, if we want to truncate in the middle (so, showing the extension), we need to explicit the max number of characters.
No worries! Gotcha! Thanks! 🙇 |
), | ||
enableSorting: false, | ||
}, | ||
featuredImageField, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we're moving the dataviews fields to the fields package one by one 👍 and fixing them (removing dependencies...)
packages/fields/src/actions/utils.ts
Outdated
@@ -34,10 +34,10 @@ export function getItemTitle( item: Post ) { | |||
if ( typeof item.title === 'string' ) { | |||
return decodeEntities( item.title ); | |||
} | |||
if ( 'rendered' in item.title ) { | |||
if ( item.title && 'rendered' in item.title ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case do we call this function with a non existent item.title ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember encountering some errors in the past, which led me to add this check. However, I’m no longer able to replicate the issue. I’m happy to revert the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted the changes with b039310.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work here.
I know the constraint of "no layout" in render is creating a non ideal result in the list view but hopefully we can address later with a better solution.
(looks like you need to run. |
I think we should follow-up by having a special callback |
Fixed with 42f90f4. |
@gigitux Do you think this one is something you can help with? It feels like the most important follow-up here. |
Thanks for your review! Based on our discussion, I created three issues:
Yes, I will work on #66338! |
1d0809a
to
e77b93b
Compare
} | ||
} | ||
|
||
.dataforms-layouts-panel__field-control { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do absorb this for any field of type media so consumers don't have to use dataviews classes (they're not public API). Would it be resolved if we add a dataviews type media
that absorbs these styles and the "featured media field" uses?
|
||
export const FeaturedImageView = ( { | ||
item, | ||
}: DataViewRenderFieldProps< BasePost > ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this could be implemented in a way that is not specific to "featured media", but rather to a media
type. For example, what if we do something along these lines:
FeaturedImageView = ({
item,
}) {
const url = item.getValue();
return (<img src={ url } );
}
If this was a media
type field, the field "featured media" could be declared as:
{
id: 'featured-media',
type: 'media',
getValue: () => { /* convert item to URL here */ },
}
This means that field types would also provide a render
default. I think we should assume field types should provide default for every field property.
@oandregal yeah, my main idea there (not sure if it's tracked) is to remove the "layout" type in the "form" config and instead have a "form.fields" config that is like that:
or something like that. |
This is something that we are planning to work on it soon... cc @louwie17 |
What?
Part of #64519
This PR adds the Featured Image Control for the Page view.
Screen.Capture.on.2024-09-18.at.18-09-37.mov
View mode
Edit
Additional Changes
Render component and view prop
With this PR, the render component will now receive the view prop. This addition is necessary because the component’s layout needs to adapt based on the view. Similar cases include the Title field, where different layouts are required depending on the view.
gutenberg/packages/edit-site/src/components/post-fields/index.js
Lines 163 to 164 in 8356977
Fix error on bulk edit mode
Screen.Capture.on.2024-09-18.at.18-01-00.mp4
Currently, there is an error when the user edits a field in bulk mode. This PR fixes this error.
Attachment type
This PR updates the
Attachment
type.Why?
How?
Testing Instructions
Ensure that
Quick Edit in DataViews
andQuick Edit in DataViews
are enabled.Testing Instructions for Keyboard
Screenshots or screencast